#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int a[53];
string s;
long long pre[11][53],suf[11][53];
int cnt[11];
long long C[53][53];
int T;
int Calc()
{
	memset(cnt,0,sizeof(cnt));
	for(int i = 0;s[i];i++)
		cnt[s[i] - '0']++;
	int mx = 10;
	for(int i = 0;i < 10;i++) if(cnt[i] >= cnt[mx])
		mx = i;
	return mx;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("give.in","r",stdin);
	freopen("give.out","w",stdout);
	cin >> T;
	while(T--)
	{
		cin >> s;
		int n = 0;
		for(int i = 0;s[i];i++)
			a[++n] = (s[i] - '0');
		memset(C,0,sizeof(C));
		C[0][0] = 1;
		for(int i = 1;i <= n;i++)
		{
			C[i][0] = 1;
			for(int j = 1;j <= i;j++)
				C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
		}
		long long ans = Calc();
		memset(cnt,0,sizeof(cnt));
		for(int k = 1;k <= n;k++)
		{
			int rst = n - k;
			for(int na = 0;na < a[k];na++)
			{
				if(k == 1 && na == 0)
					continue;
				cnt[na]++;
				int mx = 0;
				for(int i = 0;i < 10;i++)
					mx = max(mx,cnt[i]);
				for(int w = mx;w <= n;w++)//pre:<=w,suf:<w
				{
					memset(pre,0,sizeof(pre)),memset(suf,0,sizeof(suf));
					pre[0][0] = 1;
					for(int i = 1;i <= 10;i++)
						for(int s = rst;~s;s--)
							for(int j = 0;cnt[i - 1] + j <= w && j <= s;j++)
								(pre[i][s] += pre[i - 1][s - j] * C[s][j]) %= mod;
					suf[10][0] = 1;
					for(int i = 9;i;i--)
						for(int s = rst;~s;s--)
							for(int j = 0;cnt[i] + j < w && j <= s;j++)
								(suf[i][s] += suf[i + 1][s - j] * C[s][j]) %= mod;
					for(int i = 1;i < 10;i++)
						for(int l = 0,r = rst - (w - cnt[i]);r >= 0;l++,r--)
							(ans += C[rst][l] * C[rst - l][r] % mod * pre[i][l] % mod * suf[i + 1][r] % mod * i % mod) %= mod;
				}
				cnt[na]--;
			}
			cnt[a[k]]++;
		}
		for(int k = 2;k <= n;k++)
		{
			int rst = n - k;
			for(int na = 1;na < 10;na++)
			{
				memset(cnt,0,sizeof(cnt));
				int mx = cnt[na] = 1;
				for(int w = mx;w <= n;w++)//pre:<=w,suf:<w
				{
					memset(pre,0,sizeof(pre)),memset(suf,0,sizeof(suf));
					pre[0][0] = 1;
					for(int i = 1;i <= 10;i++)
						for(int s = rst;~s;s--)
							for(int j = 0;cnt[i - 1] + j <= w && j <= s;j++)
								(pre[i][s] += pre[i - 1][s - j] * C[s][j]) %= mod;
					suf[10][0] = 1;
					for(int i = 9;i;i--)
						for(int s = rst;~s;s--)
							for(int j = 0;cnt[i] + j < w && j <= s;j++)
								(suf[i][s] += suf[i + 1][s - j] * C[s][j]) %= mod;
					for(int i = 1;i < 10;i++)
						for(int l = 0,r = rst - (w - cnt[i]);r >= 0;l++,r--)
							(ans += C[rst][l] * C[rst - l][r] % mod * pre[i][l] % mod * suf[i + 1][r] % mod * i % mod) %= mod;
				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}